<?php

/**
 * Created by PhpStorm.
 * Author: ls
 * Time: 2023/9/21 11:17
 * Desc: 用户登录
 */
class Request_Api_V2_Member_Login extends Request_Api_V2_Base
{
    public function __construct($request_param)
    {
        parent::__construct($request_param);
    }

    public function login_by_user()
    {
        $this->rules = [
            ['user', ['not_empty']],
            ['pwd', ['not_empty']],
            ['captcha_key', ['not_empty']],
            ['code', ['not_empty']],
        ];

        if (isset($this->request_param['user'])) {
            $user_type = strpos($this->request_param['user'], '@') !== false ? 'email' : 'phone';
            $this->validation->rule('user', $user_type);
        }

        return $this;
    }

    public function login_by_mini_program()
    {
        if (empty($this->request_param['authorizer_appid'])) {
            $rules = [
                ['code', ['not_empty']],
            ];
        } else {
            $rules = [
                ['wxSns', ['not_empty']],
            ];
        }
        $this->rules = $rules;

        return $this;
    }

    public function get_phone_by_mini_program()
    {
        $this->rules = [
            ['sessionKey', ['not_empty']],
            ['encryptedData', ['not_empty']],
            ['iv', ['not_empty']],
        ];

        return $this;
    }

    public function login_by_toutiao()
    {
        $this->rules = [
            ['code', ['not_empty']],
            ['user_info', ['not_empty']]
        ];

        return $this;
    }

    public function get_phone_by_toutiao_program()
    {
        $this->rules = [
            ['sessionKey', ['not_empty']],
            ['encryptedData', ['not_empty']],
            ['iv', ['not_empty']]
        ];

        return $this;
    }

    public function login_by_alipay()
    {
        $this->rules = [
            ['authCode', ['not_empty']]
        ];

        return $this;
    }

    public function login_by_phone()
    {
        $this->rules = [
            ['comefrom', ['not_empty', $this->rule_in_array(['wechat', 'h5', 'toutiao', 'zhifubao'])]],
            ['mobile', ['not_empty', 'phone']],
        ];

        return $this;
    }

}